package com.bjshiwei.zhengu.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjshiwei.zhengu.R;
import com.bjshiwei.zhengu.bean.IndividualBean;

import java.util.List;

/**
 * 作者：Administrator on 2016/10/14 0014 14:02
 * 邮箱：sanjins@126.com
 */


public class IndividualAdapter extends MyBaseAdapter<IndividualBean.DataBean>{
    private List<IndividualBean.DataBean> mData;
    private Context mContext;
    public IndividualAdapter(Context context, List<IndividualBean.DataBean> datas) {
        super(context, datas);
        mContext =context;
        mData = datas;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_individual_detail, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if(!TextUtils.isEmpty(mData.get(position).getName().toString().trim())) {
            viewHolder.mTextViewName.setText(mData.get(position).getName().toString().trim());
        }

        if(!TextUtils.isEmpty(mData.get(position).getCode().toString().trim())) {
            viewHolder.mTextViewCode.setText(mData.get(position).getCode().toString().trim());
        }

        if(!TextUtils.isEmpty(mData.get(position).getChange().toString().trim())) {
            if(mData.get(position).getChange().toString().trim().contains("-")) {
                viewHolder.mTextViewChange.setTextColor(mContext.getResources().getColor(R.color.green));
                viewHolder.mTextViewChange.setText(mData.get(position).getChange().toString().trim());
            }else{
                viewHolder.mTextViewChange.setTextColor(mContext.getResources().getColor(R.color.market_red));
                viewHolder.mTextViewChange.setText("+"+mData.get(position).getChange().toString().trim());
            }

        }

        if(!TextUtils.isEmpty(mData.get(position).getLastprice().toString().trim())) {
            viewHolder.mTextViewLastPrice.setText(mData.get(position).getLastprice().toString().trim());
        }


        /*if(position==(mData.size()-1)) {
            viewHolder.viewLine.setVisibility(View.VISIBLE);
        }*/

        return convertView;
    }

    class ViewHolder{
        private TextView mTextViewName,mTextViewCode,mTextViewChange,mTextViewLastPrice;
        private View viewLine;

        public ViewHolder(View view){
            mTextViewName = (TextView) view.findViewById(R.id.tv_individual_name);
            mTextViewCode = (TextView) view.findViewById(R.id.tv_individual_id);
            mTextViewLastPrice = (TextView) view.findViewById(R.id.tv_individual_price);
            mTextViewChange = (TextView) view.findViewById(R.id.tv_individual_changerate);
            viewLine = view.findViewById(R.id.v_individual_end_line);
            View inflate = View.inflate(mContext, R.layout.fragment_individual_detail, null);
        }
    }


}
